package cn.kgc.springboot.controller;

import cn.kgc.springboot.entity.Student;
import cn.kgc.springboot.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/9/6
 * @description 处理前端发送的有关student相关的请求
 * <p>
 * 学生模块的请求
 * 1.查询学生分页数据
 * 2.添加学生信息
 * 3.删除学生信息
 * 4.修改学生信息
 * 5.搜索学生
 * <p>
 * 请求方式的编写
 * /student/select  查询
 * /student/add   新增
 * /student/update   更新
 * /student/delete   删除
 * <p>
 * /teacher
 */
@RestController  //  标识当前类是一个控制类   可以接收前端的请求
@RequestMapping("student")
public class StudentController {

    //  注入student的业务层
    @Resource
    private StudentService studentService;

    //  查询学生信息    /student/select
    @RequestMapping("select")
    public List<Student> selectAll() {
        List<Student> list = studentService.list();
        return list;
    }

    //  添加学生信息    /student/add
    @RequestMapping("add")
    public Boolean addStudent(Student student) {
        boolean save = studentService.save(student);

        return save;
    }

    //  修改学生信息  /student/update
    @RequestMapping("update")
    public Integer updateStudent(Student student) {
        studentService.updateById(student);
        return null;
    }

    //  删除学生信息   /student/delete
    @RequestMapping("delete")
    public Boolean deleteOne(Integer id) {
        System.out.println("id = " + id);
        boolean b = studentService.removeById(id);
        return b;
    }

}
